Investigating Second Eigenvalue

  library(pacman)
  pacman::p_load(PageRank, devtools, Matrix, igraph, mise, tidyverse, rgl, latex2exp, plotly)
#  mise()

Looking at Density

Constants

Define some constants

n <- 20
p <- 1:n/n
beta <- 1:n/n
beta <- runif(n)*100
#sz <- 1:n/n+10
sz <- (1:n/n)*100+10
input_var <- expand.grid("n" = n, "p" = p, "beta" = beta, "size" = sz)
head(input_var)
##    n    p     beta size
## 1 20 0.05 15.79875   15
## 2 20 0.10 15.79875   15
## 3 20 0.15 15.79875   15
## 4 20 0.20 15.79875   15
## 5 20 0.25 15.79875   15
## 6 20 0.30 15.79875   15

Function to Build Graph

random_graph <- function(n, p, beta, size) {
      g1 <- igraph::erdos.renyi.game(n = sz, p)
      A <- igraph::get.adjacency(g1) # Row to column
      A <- Matrix::t(A)

      A_dens <- mean(A)
      T      <- PageRank::power_walk_prob_trans(A)
      e2     <- eigen(T, only.values = TRUE)$values[2] # R orders by descending magnitude
      A_det  <- det(A)
      return(c(abs(e2), A_dens, A_det))
}

Return results

Map the function

nc <- length(random_graph(1, 1, 1, 1))
Y <- matrix(ncol = nc, nrow = nrow(input_var))
for (i in 1:nrow(input_var)) {
  X <- as.vector(input_var[i,])
  Y[i,] <-  random_graph(X$n, X$p, X$beta, X$size)
}
if (sum(abs(Y) != abs(Re(Y))) == 0) {
  Y <- Re(Y)
}
nrow(input_var)
## [1] 8000
nrow(Y)
## [1] 8000
Y <- as.data.frame(Y); colnames(Y) <- c("eigenvalue2", "density", "determinant")
(data <- cbind(input_var, Y)) %>% head()
##    n    p     beta size eigenvalue2    density determinant
## 1 20 0.05 15.79875   15   0.4826803 0.05333333           0
## 2 20 0.10 15.79875   15   0.5422629 0.09777778           0
## 3 20 0.15 15.79875   15   0.5180648 0.13333333           0
## 4 20 0.20 15.79875   15   0.5326807 0.16888889          -2
## 5 20 0.25 15.79875   15   0.4984123 0.18666667           0
## 6 20 0.30 15.79875   15   0.5493350 0.30222222          -4
data <- data[data$density!=0,]

Plot Results

chival <- dchisq(seq(from = 0, to = 40, length.out = 100), df = 10)*7
index  <- seq(from = 0, to = 2.2, length.out = 100)
chidata  <- data.frame(index = index, chi = chival)
ggplot(data) +
  geom_point(mapping = aes(x = density, y = eigenvalue2, size = beta, color = size, shape = factor(n))) +
  scale_size_continuous(range = c(0.1,1)) +
  labs(x = "Density of Adjacency Matrix", y = TeX("$\\xi_2$ of $T_{PW}$"))

This is interesting, lets look at a snapshot of it:

pairs(data)

So it seems that the only things that generally affect \(\xi_2\) across all possible adjacency matrices are density and determinant of \(\mathbf{A}\), so let’s look at that:

library(plotly)

mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)

d <- data[sample(1:nrow(data), 1000),]

fig <- plot_ly(d, x = ~determinant, y = ~density, z = ~eigenvalue2)
fig <- fig %>% add_markers(size = 1)
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Determinant'),
                     yaxis = list(title = 'density'),
                     zaxis = list(title = '2nd Eigenvalue')))

fig
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.